package com.zlm.IO.CharStream.FileReader;

import java.io.FileReader;
import java.io.IOException;

/**
 * @author 13026
 */
public class FileReader_demo {
    /*
     * FileReader
     * 字符输入流
     *
     * public FileReader(File file)
     * public FIleReader(String pathname)
     *
     * 按字节进行读取，遇到中文，一次读多个字节，读取后解码成10进制，返回一个整数
     * public int read()         一次读取一个，读到末尾返回-1
     * public int read(char[] c) 一次读取多个，读取到末尾返回-1
     *
     * public int close()        释放资源，关流
     * */
    public static void main(String[] args) throws IOException {
        FileReader fr = new FileReader("D:\\myProject\\javaTest\\oneModule\\src\\com\\zlm\\IO\\CharStream\\FileReader\\FilesPackage\\a.txt");
        int b;
        while ((b = fr.read()) != -1) {
            System.out.println(b + "=" + (char) b);
        }
        fr.close();

        // 读取数据，解码，强转合并，把强转的字符放到数组中
        FileReader fr2 = new FileReader("D:\\myProject\\javaTest\\oneModule\\src\\com\\zlm\\IO\\CharStream\\FileReader\\FilesPackage\\a.txt");
        char[] chars = new char[2];
        int length;
        while ((length = fr2.read(chars)) != -1) {
            System.out.println(new String(chars, 0, length));
        }
        fr2.close();
    }
}
